/**
 * 所属项目：北京慧点科技有限公司XCOA产品。
 * 注意：本内容仅限于内部传阅，禁止外泄以及用于其他的商业目的。
 *
 * @Date: 2021/9/2
 * @Copyright: Copyright 2020 © Smartdot Technologies Co., Ltd.
 */

package com.hd.center.message.business.demo;


import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hd.center.message.base.base.convertInfo.SendInfo;
import com.hd.center.message.base.base.result.BaseResult;
import com.hd.center.message.base.message.template.SendTemplate;
import com.hd.center.message.mq.core.CmmqRabbitTemplate;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 测试样例
 * 
 * @class: SendMessageController
 * @date 2021/9/2 11:07
 * @author <a href="mailto:zhoufei@smartdot.com">周飞</a>
 * @Verson 1.0 -2021/9/2 11:07
 * @see
 */
@RestController
public class Demo_SendMessageController2 {
    

    @Autowired
    SendTemplate sendTemplate;

    @Autowired
    RabbitTemplate rabbitTemplate; // 使用RabbitTemplate,这提供了接收/发送等等方法


    @RequestMapping("/sendDirectMessage2")
    public Object sendDirectMessage2() {
        BaseResult send = sendTemplate.sendMessage(SendInfo.demoBuildSendInfo());
        return send;
    }



    @RequestMapping("/sendDirectMessage3")
    public String sendDirectMessage3() {
        String messageId = String.valueOf(UUID.randomUUID());
        String messageData = "test message, hello!";
        String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        Map<String, Object> map = new HashMap<>();
        map.put("messageId", messageId);
        map.put("messageData", messageData);
        map.put("createTime", createTime);
        // 将消息携带绑定键值：TestDirectRouting 发送到交换机TestDirectExchange
        rabbitTemplate.convertAndSend("TestDirectExchange", "TestDirectRouting", map);
        return "ok";
    }
    
}